<template>
  <div class="level">
    <h1>医院</h1>
    <div class="content">
      <div class="left">等级:</div>
      <ul class="hospital">
        <li :class="{active:levelvalue==''}" @click="changeLevel('')">全部</li>
        <li v-for="(level,index) in levelArr" :key="level.id" :class="level.value==levelvalue?'active':''" @click="changeLevel(level.value)">{{level.name}}</li>
      </ul>
    </div>
  </div>
</template>

<script setup lang="ts">
import {ref,onMounted} from 'vue'
import {reqHospitalLevelAndRegion} from '@/api/home/index'
import type {HospitalLevelAndRegion,HospitalLevelAndRegionResponseData} from '@/api/home/type'
let levelArr = ref<HospitalLevelAndRegion[]>([])
let levelvalue = ref<string>('')
  onMounted(()=>{
    getHospitalLevel()
  })
// 获取医院等级与地区信息
const getHospitalLevel = async ()=>{
  let res:HospitalLevelAndRegionResponseData = await reqHospitalLevelAndRegion("HosType")
  if(res.code==200){
    levelArr.value = res.data
  }
}
const changeLevel = (level:string)=>{
  levelvalue.value = level
  $emit('getLevel',level)
}
let $emit = defineEmits(['getLevel'])
</script>

<style scoped lang="scss">
.level {
  color: #7f7f7f;
  margin-top: 20px;
  h1 {
    font-weight: 900;
    margin: 10px 0px;
  }
  .content {
    display: flex;
    .left {
      margin-right: 10px;
    }
    .hospital {
      display: flex;
      li {
        margin-right: 10px;
        &.active {
          color: #55a6fe;
        }
      }
      li:hover {
        color: #55a6fe;
        cursor: pointer;
      }
    }
  }
}
</style>
